﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;

namespace RooHui.Infrastructure.Entities.Repository
{
     [Table("P_Province")]
    public class P_Province:IEntity<P_Province>
    {
         [Key]
         [Column(TypeName = "varchar")]
        [StringLength(10)]
        public string ProvinceCode { get; set; }
         [Column(TypeName = "varchar")]
         [StringLength(50)]
         public string ProvinceName { get; set; }

         public override P_Province Find(string key)
         {

             return Find(c => c.ProvinceCode == key);
         }

         public override P_Province Find(System.Linq.Expressions.Expression<Func<P_Province, bool>> where)
         {
             using (Context ctx = new Context())
             {
                 var item = ctx.Province.FirstOrDefault(where);
                 if (item != null)
                 {
                     this.ProvinceCode = item.ProvinceCode;
                     this.ProvinceName = item.ProvinceName; 
                     return this;
                 }
                 return null;
             }
         }

         public override bool Any(System.Linq.Expressions.Expression<Func<P_Province, bool>> where)
         {
             using (Context ctx = new Context())
             {
                 return ctx.Province.Any(where);
             }
         }
    }
}
